﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using BUS;
using Share;
using Entity;

namespace SLMNG
{
    public partial class FrmAutoNumber : BaseForm
    {
        public FrmAutoNumber()
        {
            InitializeComponent();
            this.Load += new EventHandler(AutoNumber_Load);
            tbAction.AllowPrint = false;
            tbMain.SelectedPageChanged += new DevExpress.XtraTab.TabPageChangedEventHandler(tbMain_SelectedPageChanged);
        }

        void tbMain_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e)
        {
            if (tbMain.SelectedTabPageIndex == 0)
            {
                base.SetToolbarButton(TabpageName.Category);
            }
            else
            {
                SetToolbarButton(TabpageName.Action);
            }
        }

        void AutoNumber_Load(object sender, EventArgs e)
        {
            string[] arg = new string[] { };
            object[] obj = new object[] { DBNull.Value };
            DataSet ds1 = CatalogueBase.GetData(AutoNumber.STORE_GET_ALL, arg, obj);
            gridControl1.DataSource = ds1.Tables[0];
        }

        public void Save()
        {
            if (tbMain.SelectedTabPageIndex == 1)
            {
                if(string.IsNullOrEmpty(txtServiceID.Text))
                {
                    MessageBox.Show(temp.ID_IS_NOT_NULL);
                    return;
                }
                else if(string.IsNullOrEmpty(txtServiceName.Text))
                {
                    MessageBox.Show(temp.NAME_IS_NOT_NULL);
                    return;
                }

                string[] arg = new string[] { "ServiceID", "ServiceName","ServiceTypeID","Price","Commission", "IsDeleted" };
                object[] obj = new object[] { txtServiceID.Text.Trim(), txtServiceName.Text.Trim(),
                                                lkeServiceType.EditValue, lkePrice.EditValue,
                                                lkeCommission.EditValue, chkStatus.Checked };
                string result = CatalogueBase.SaveData("usp_Services_Insert", arg, obj);
                if (result == "0")
                    MessageBox.Show(temp.STATUS_INSERT_SUCCESS);
                else
                    MessageBox.Show(temp.STATUS_INSERT_ERROR);

            }
        }

        public override void fncInsert()
        {
            tbMain.SelectedTabPageIndex = 1;
        }

        public override void fncSave()
        {
            throw new NotImplementedException();
        }

        public override void fncEdit()
        {
            throw new NotImplementedException();
        }

        public override void fncDelete()
        {
            throw new NotImplementedException();
        }

        public override void fncRefresh()
        {
            throw new NotImplementedException();
        }

        public override void fncPrint()
        {
            throw new NotImplementedException();
        }

        #region Toolbar

        protected override void OnVisibleChanged(EventArgs e)
        {
            if (this.Visible == true)
            {
                if (tbMain.SelectedTabPageIndex == 0)
                {
                    base.SetToolbarButton(TabpageName.Category);
                }
                else
                {
                    SetToolbarButton(TabpageName.Action);
                }
            }
            base.OnVisibleChanged(e);
        }

        #endregion
    }
}
